package cn.simple.parser;

import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;

import static com.intellij.psi.TokenType.BAD_CHARACTER;
import static com.intellij.psi.TokenType.WHITE_SPACE;
import static cn.simple.language.psi.SimpleTypes.*;

%%

%{
  public _SimpleLexer() {
    this((java.io.Reader)null);
  }
%}

%public
%class _SimpleLexer
%implements FlexLexer
%function advance
%type IElementType
%unicode

EOL=\R
WHITE_SPACE=\s+

HTTP_REQUEST_COMMENT_REGEXP=###.+\n
HTTP_REQUEST_REGEXP=(GET|POST)[^#]+\n*
STR=(`.+?`)|('.+?')|(\".+?\")|([^\s\n:{},]+)
NUM=[0-9]+
CRTL=\n
WS=[ \t\n\x0B\f\r]+

%%
<YYINITIAL> {
  {WHITE_SPACE}                       { return WHITE_SPACE; }


  {HTTP_REQUEST_COMMENT_REGEXP}       { return HTTP_REQUEST_COMMENT_REGEXP; }
  {HTTP_REQUEST_REGEXP}               { return HTTP_REQUEST_REGEXP; }
  {STR}                               { return STR; }
  {NUM}                               { return NUM; }
  {CRTL}                              { return CRTL; }
  {WS}                                { return WS; }

}

[^] { return BAD_CHARACTER; }
